
import { commonConstants } from 'hhlt-core/constants'
import { systemUtils} from 'hhlt-core/utils'
import { formatUtils,requestUtils} from 'hhlt-vue/utils'
import { IPageInfo} from 'hhlt-core/src/model/page/pageInfo'
import { IDataTablePager} from 'hhlt-core/src/model/page/dataTablePager'
import { VxeGridPropTypes, VxeTableDefines } from 'vxe-table'
import { IColumnInfo} from 'hhlt-core/src/model/form/column'
import { IExecuteData} from 'hhlt-core/src/model/base/resultModel'
import { FormRules } from 'element-plus'
import { fixedDatasource} from "hhlt-core/constants"
import { objectUtils } from 'hhlt-core/utils'
import { requestContextPath } from 'lxsh-cer-web-pc/src/constants'
import { ICerTypeGroup, ICerTypeGroupQO, ICerTypeGroupVO,CerTypeGroup } from 'lxsh-cer-web-pc/src/model/cer/cer/type-group/cer-type-group'
/**
* 减碳资源类别及资源系数维护业务实现
*/
export default {
//获取页面信息，根据不同的功能编码来加载不同的页面
getPageInfo:function(pageInfo:IPageInfo<ICerTypeGroup>){
  this.getColumnInfo()
},
/**
* 获取列信息
*/
getColumnInfo(successCallback?:(columnsParam:VxeGridPropTypes.Columns)=>void){
    var columns:VxeGridPropTypes.Columns = [
      { type: 'checkbox', width: 50 },
      { type: 'seq', width: 60,align:'center',title:'序号' },
      { field: 'id', title: '主键ID', visible:false },
      { field: 'groupData', title: '分组', showOverflow: true, sortable: true,width:'100px' },
      { field: 'improType', title: '类别', showOverflow: true, sortable: true,width:'100px' },
      { field: 'energyUnit', title: '能耗单位', showOverflow: true, sortable: true,width:'100px' },
      { field: 'coefficient', title: '系数', showOverflow: true, sortable: true,width:'100px' },
      { field: 'remark', title: '备注', showOverflow: true, sortable: true,width:'100px' },
      { field: 'addUserName', title: '添加者名', showOverflow: true, sortable: true,width:'100px' },
      { field: 'addDate', title: '添加时间', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { title: '操作', width: 200, slots: { default: 'operate' },fixed:'right' }
    ];
    if(successCallback){
      successCallback(columns);
    }
  },
  /**
   * 获取检索条件
   */
  getSearchCondition(successCallback:(searchCondtionParam:IColumnInfo[],queryParams:ICerTypeGroupQO) => void){
    var searchCondition = [
      { columnCode: 'groupData', columnName: '分组', basicControlType:commonConstants.enumBasicControlType.COMBOBOX,defaultValue:"",controlAttrValue:requestContextPath.cer + '/cer/groupData/getComboList',controlNeedValue:'' },
      { columnCode: 'improType', columnName: '类别', basicControlType:commonConstants.enumBasicControlType.COMBOBOX,defaultValue:"",controlAttrValue:requestContextPath.cer + '/cer/reduceType/getComboList',controlNeedValue:'' },
    ];
    var queryParam:ICerTypeGroupQO = {
        id:undefined,
       /**
	    * groupData:分组
	    */
    groupData:"",
       /**
	    * improType:类别名称
	    */
    improType:"",
    }
    return successCallback(searchCondition,queryParam);
  },
  /**
   * 单条删除操作
   */
  doDeleteSingle(selectItem:ICerTypeGroupVO,successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/typeGroup/deleteByLogicBatch';
    let list = new Array();
    let item:ICerTypeGroupQO = {
      id:selectItem.id
    }
    list.push(item)
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 单条删除操作
   */
  doDeleteBatch(selectList:ICerTypeGroupVO[],successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/typeGroup/deleteByLogicBatch';
    let list = new Array();
    for (let selectItem of selectList) {
      let item :ICerTypeGroupVO = {
        id:selectItem.id
      };
      list.push(item);
    }
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 获取分页数据
   */
  getListByPager(queryParam:ICerTypeGroupQO,pager:IDataTablePager<ICerTypeGroupVO>,successCallback?:(queryResult:IExecuteData<IDataTablePager<ICerTypeGroupVO>>) => void):Promise<IExecuteData<IDataTablePager<ICerTypeGroupVO>>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/typeGroup/getListByPager';
    return  requestUtils.getListByPager(url, queryParam, pager,successCallback)
  },
  addForm(formData:ICerTypeGroup,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/typeGroup/insert";
    return requestUtils.insert(url, formData,successCallback);
  },
  updateForm(formData:ICerTypeGroup,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/typeGroup/update";
    return requestUtils.update(url, formData,successCallback);
  },
  updateEnable(formData:ICerTypeGroup,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/typeGroup/updateEnable";
    return requestUtils.update(url, formData,successCallback);
  },
  getInfoByCondition(param:ICerTypeGroupQO,successCallback?:(result:IExecuteData<ICerTypeGroupVO>) => void):Promise<IExecuteData<ICerTypeGroupVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/typeGroup/getInfoByCondition";
    return requestUtils.getInfoByCondition(url, param,successCallback);
  },
  //获取表单项
  getFormDataItem(successCallback:(formData:ICerTypeGroup,verify:FormRules) => void){
    var formData:ICerTypeGroup = new CerTypeGroup()
        // 校验
    var verify:FormRules = {
        groupData: [{
            required: true,
            message: "分组不能为空！"
        }],
        improType: [{
            required: true,
            message: "类别不能为空！"
        }],
        energyUnit: [{
            required: true,
            message: "能耗单位不能为空！"
        }],
        coefficient: [{
            required: true,
            message: "系数不能为空！"
        }],
    }
    return successCallback(formData,verify)
  }
}
